package com.heihei.security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.annotation.Resource;

/**
 * ServletContext配置
 *
 * @author duanhengfei
 * @version 1.0
 * @date 2020/6/26 21:52
 * @since JDK1.8
 */
@Configuration  //相当于springmvc.xml文件
@EnableWebMvc
@ComponentScan(basePackages = "com.heihei.security",
        includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class)})
public class WebConfig implements WebMvcConfigurer {
    //视图解析器
    @Bean
    public InternalResourceViewResolver viewResolver(){
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //spring security默认提供的登录页面  redirect:/login
        registry.addViewController("/").setViewName("redirect:login");
    }

    //注：Spring Security 提供了认证授权拦截功能，不需要再自己独立的建立拦截器
}